import esriLoader from 'esri-loader'
import {
  esriLoaderUrl,
  esriLoaderCss,
} from '../../../public/arcgisParam/arcgisParam'

export class EsriNameSpace {
  constructor() {}
  initNameSpace() {
    this.arcgisLoadOption = {
      url: esriLoaderUrl,
      css: esriLoaderCss,
    }
    return new Promise(async (resolve, reject) => {
      // Load the modules for the ArcGIS API for JavaScript
      const [
        Map,
        MapView,
        SceneView,
        WebTileLayer,
        GraphicsLayer,
        Graphic,
        Sketch,
        geometryEngine,
        webMercatorUtils,
        TileLayer,
        SpatialReference,
        WMSLayer,
        TileInfo,
        ElevationLayer,
        FeatureLayer,
        urlUtils,
        GeoJSONLayer,
        Point,
      ] = await esriLoader.loadModules(
        [
          'esri/Map',
          'esri/views/MapView', //2d视图模块
          'esri/views/SceneView', //3d视图模块
          'esri/layers/WebTileLayer',
          'esri/layers/GraphicsLayer',
          'esri/Graphic',
          'esri/widgets/Sketch',
          'esri/geometry/geometryEngine',
          'esri/geometry/support/webMercatorUtils',
          'esri/layers/TileLayer',
          'esri/geometry/SpatialReference',
          'esri/layers/WMSLayer',
          'esri/layers/support/TileInfo',
          'esri/layers/ElevationLayer',
          'esri/layers/FeatureLayer',
          'esri/core/urlUtils',
          'esri/layers/GeoJSONLayer',
          'esri/geometry/Point',
        ],
        this.arcgisLoadOption
      )
      // config.fontsUrl = mapInfo.FontsUrl
      this.Map = Map
      this.MapView = MapView
      this.SceneView = SceneView
      this.WebTileLayer = WebTileLayer
      this.GraphicsLayer = GraphicsLayer
      this.Graphic = Graphic
      this.Sketch = Sketch
      this.geometryEngine = geometryEngine
      this.webMercatorUtils = webMercatorUtils
      this.TileLayer = TileLayer
      this.SpatialReference = SpatialReference
      this.WMSLayer = WMSLayer
      this.TileInfo = TileInfo
      this.ElevationLayer = ElevationLayer
      this.FeatureLayer = FeatureLayer
      urlUtils.addProxyRule({
        urlPrefix: 'http://218.94.6.92:6080/arcgis/rest/services',
        proxyUrl: 'http://localhost:8089' + '/DotNet/proxy.ashx',
      })
      this.GeoJSONLayer = GeoJSONLayer
      this.Point = Point
      resolve()
    })
  }
}
